package 单调栈;

import java.util.Deque;
import java.util.LinkedList;

// 739 每日温度
public class Solution1 {
    public int[] dailyTemperatures(int[] temperatures) {
        Deque<Integer> stack = new LinkedList();
        int[] res = new int[temperatures.length];
        for(int i = 0 ; i < temperatures.length ; i++){
            while(!stack.isEmpty()&&temperatures[stack.peek()]<temperatures[i]){
                int top = stack.poll();
                res[top] = i-top;
            }
            stack.push(i);
        }
        return res;
    }
}
